package com.thunbu.lib_common.utils.kick;

import io.reactivex.Emitter;
import io.reactivex.Observable;
import io.reactivex.observables.ConnectableObservable;
import io.reactivex.schedulers.Schedulers;

/**
 * Description:
 * Created by :huangshanshan@geely.com
 * Date: 2018/8/13.
 */
public class LogoutMonitor {
    private static volatile LogoutMonitor sDataMonitor = null;
    private ConnectableObservable<KickInfo> connectObservable;
    private Emitter<KickInfo> mEmitter;

    private LogoutMonitor() {
        Observable<KickInfo> observable = Observable.create(emitter -> mEmitter = emitter);
        connectObservable = observable.observeOn(Schedulers.io()).publish();
        connectObservable.connect();
    }

    public static LogoutMonitor getInstance() {
        if (sDataMonitor == null) {
            synchronized (LogoutMonitor.class) {
                if (sDataMonitor == null) {
                    sDataMonitor = new LogoutMonitor();
                }
            }
        }
        return sDataMonitor;
    }

    public ConnectableObservable<KickInfo> getDataMonitor() {
        return connectObservable;
    }

    public void emitter(KickInfo data) {
        mEmitter.onNext(data);
    }

}
